package PrearedStatement完成增删改.test01;

import java.sql.*;
import java.util.ResourceBundle;

public class Test01 {
    public static void main(String[] args) {
        ResourceBundle bundle = ResourceBundle.getBundle("jdbc");
        Connection conn = null;
        PreparedStatement ps = null;
        try {
            Class.forName(bundle.getString("driver"));
            conn = DriverManager.getConnection(bundle.getString("url"),bundle.getString("user"),bundle.getString("password"));
            /*
            ps = conn.prepareStatement("insert into dept(deptno,dname,loc) values(?,?,?)");

            ps = conn.prepareStatement("update dept set dname = ?,loc = ? where deptno = ?");
            ps.setInt(3,50);
            ps.setString(1,"武器部");
            ps.setString(2,"叙利亚");
            */
            ps = conn.prepareStatement("delete from dept where deptno = ?");
            ps.setInt(1,50);
            int count = ps.executeUpdate();
            System.out.println(count == 1 ? "修改成功" : "修改失败");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally{
            if (ps != null) {
                try {
                    ps.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
